Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Extending a promise leads to "Promise resolve or reject function is not callable" when attempting to await it
class ControllablePromise extends Promise {
    constructor() {
        let resolveClosure = null;
        let rejectClosure = null;
        super((resolve, reject) => {
            resolveClosure = resolve;
            rejectClosure = reject;
        });

        this.resolveClosure = resolveClosure;
        this.rejectClosure = rejectClosure;
    }
}
const prom = new ControllablePromise();

async function func(){
  try{
    await prom;
    console.log('done');
  }
  catch(err){
    console.log(err.message);
  }
}


setTimeout(() => {prom.rejectClosure(); console.log('resolved');}, 1000);
func();

I am attempting to create a promise that I can resolve/reject externally. I can do this functionally without issue, just returning a regular promise after I attach the resolve/reject closures to it, but when attempting to turn it into a class I am running into difficulty. The code above throws an error when attempting to await the promise. Why is this happening exactly?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!